package com.ttg.utils.connection.handler;

//~--- non-JDK imports --------------------------------------------------------

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ResponseHandler;
import org.apache.http.util.EntityUtils;

import java.io.IOException;
import java.nio.charset.Charset;

//~--- JDK imports ------------------------------------------------------------

//~--- classes ----------------------------------------------------------------

/**
 * Class StringResponseHandler
 * Description
 * Create 2016-02-25 01:04:29 
 * @author Ardy    
 */
public class StringResponseHandler implements ResponseHandler<String> {

    /**
     * Method handleResponse 
     * Description 说明：
     *
     * @param response 说明：
     *
     * @return 返回值说明：
     *
     * @throws IOException 异常：
     */
    public String handleResponse(HttpResponse response) throws IOException {
        HttpEntity entity = null;
        String     var5;

        try {
            entity = ResponseHandlerHelper.handleNon2xxStatus(response);

            Charset responseCharset = ResponseHandlerHelper.getResponseCharset(entity);
            String  result          = EntityUtils.toString(entity, responseCharset);

            var5 = result;
        } finally {
            EntityUtils.consume(entity);
        }

        return var5;
    }
}


//~ Formatted by Jindent --- http://www.jindent.com
